package com.billsharing.server;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class AddUserToGroup
 */
@WebServlet("/AddUserToGroup")
public class AddUserToGroup extends HttpServlet {
	private static final long serialVersionUID = 1L;
    int gid;
    String userEmail;
 

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter out = response.getWriter();
		gid = Integer.parseInt(request.getParameter("gid"));
		userEmail = request.getParameter("userEmail");
		userEmail = userEmail.replaceAll("\\s+", "");
		System.out.println(userEmail);
		User user = new User(userEmail);
		System.out.println(user.getUid());
		Group group = new Group(gid);
		out.print(group.addUser(user));
		
	}

}
